package algorithms.leecode;

import java.util.LinkedList;

public class horner {
    public static void main(String[] args) {
        LinkedList li = new LinkedList<Object>();
        li.iterator();
        int[] a = new int[]{2,1,8,4};
        System.err.println(horner(3,a));

    }
    public static int horner(int x, int[] a) {
        long l = System.currentTimeMillis();
        int poly = 0;
        for (int i = x; i >= 0; i--) {
            poly = x * poly  + a[i];
        }
        System.err.println(System.currentTimeMillis() - l);
        System.err.println(poly);
        return poly;
    }
    
    public static void gcd(int a,int b) {
        int x = 0;
        int y = 0;
        int tpa = a % 2;
        int tpb = b % 2;
        if (tpa == 0) {
            x = a / 2;
        }
        if (tpb == 0) {
            y = b / 2;
        }
        if (tpa != 0 && tpb != 0) {
            gcd((a + b) /2,(a - b) /2);
        } else {
            gcd(x,y);
        }
    }
}
